﻿using System.Web.Mvc;
using System.Web.Routing;

namespace viBook.Filters
{
    public class ExtendedAuthentication : ExtendedAuthenticationBase
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (!IsLoggedIn)
            {
                filterContext.Result = new RedirectToRouteResult(
                                   new RouteValueDictionary 
                                   {
                                       { "Action", "LogOn" },
                                       { "Controller", "Account" }
                                   });
                return;
            }

            if (!IsActivated)
            {
                filterContext.Result = new RedirectToRouteResult(
                                      new RouteValueDictionary 
                                   {
                                       { "Action", "ActivationRequired" },
                                       { "Controller", "Account" }
                                   }); return;
            }

            if (!IsAllowToUseResource)
            {
                filterContext.Result = new RedirectToRouteResult(
                                      new RouteValueDictionary 
                                   {
                                       { "Action", "AccessDenied" },
                                       { "Controller", "Account" }
                                   }); return;
            }
        }
    }
}